import { useContext } from 'react'
import './index.scss'
import { CountContext } from '../../context'
export default function MyCount() {
  const { goods_count, changeCount, id } = useContext(CountContext)
  const increment = () => {
    changeCount(id, goods_count + 1)
  }
  const decrement = () => {
    let gc = goods_count - 1
    if (gc <= 1) {
      gc = 1
    }
    changeCount(id, gc)
  }
  return (
    <div className='my-counter'>
      <button type='button' className='btn btn-light' onClick={decrement}>
        -
      </button>
      <input
        type='number'
        className='form-control inp'
        value={goods_count}
        onChange={() => {}}
      />
      <button type='button' className='btn btn-light' onClick={increment}>
        +
      </button>
    </div>
  )
}
